<%@ page language="java" session="true"  import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.itjob.scott.entity.UserEntity"%>
<%@ page isErrorPage="true" %>
<%@ page import="java.net.URLDecoder"%>


<!-- 导入core标签库 -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!-- 导入fmt标签库 -->
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>



<!DOCTYPE HTML>
<html>
	<head>
	  <meta charset="UTF-8">
	  <title>el表达式和jstl标签</title>
	  <link rel="stylesheet" type="text/css" href="css/common.css"/>
	</head>

<body>

1：java代码：<br/>
1.1：<%out.print(((UserEntity)session.getAttribute("userEntity")).getUsername()); %><br/>
1.2：<%=((UserEntity)session.getAttribute("userEntity")).getUsername() %><br/><br/>

2：java代码转El表达式<br/>
${sessionScope.userEntity.username}<br/><br/>


3：El表达式 数组 List 运算符 <br/>

3.1：EL Array:${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]} ${arr[4]}
<br/>
3.2：EL List :${list[0]} ${list[1]} ${list[2]} ${list[3]}  ${list[4]}
<br/>
3.3：EL Map: ${requestScope.map.a} ${map.b} ${map.c} ${map.d}
<br/>
3.4：运算符:<br/>
<%="${3>5}="%> ${3 > 5}<br/>
<%="${17/5}="%> ${17/5}<br/>
<%="${17 div 5}="%> ${17 div 5}<br/>
<%="${17 % 5}="%> ${17 % 5}<br/>
<%="${17mod5}="%> ${17 mod 5}<br/>
<%="${5==5}="%> ${5==5}<br/>
<%="${5 eq 5}="%> ${5 eq 5}<br/>
<%="${5!=5}="%> ${5!=5}<br/>
<%="${5 ne 5}="%> ${5 ne 5}<br/>
<br/>

4 EL的11大内置对象之 四大作用域:<br/>
<%pageContext.setAttribute("is","d");%>
4.1:<%="${pageScope.is}="%>${pageScope.is}<br/>
4.2:<%="${requestScope.is}="%>${requestScope.is}<br/>
4.3:<%="${sessionScope.is}="%>${sessionScope.is}<br/>
4.4:<%="${applicationScope.is}="%>${applicationScope.is}<br/>
4.5:<%="${empty sessionScope.is}="%>${empty sessionScope.is}<br/>
<%--如果不写Scope 就找最小的那个 --%>
4.6:<%="${is}="%>${is}<br/>
<br/>

5: EL的11大内置对象之param
<br/>
5.1:EL:${param.age}<br/>
5.2:EL:${param.password}<br/>
5.3:<%=request.getParameter("age")%><br/>
5.4:<%=request.getParameter("password")%><br/>
5.5:EL:${param['age']}<br/><br/>

6:EL的11大内置对象之paramValues
<br/>
6.1:EL:${paramValues.gj[0]}<br/>
6.2:EL:${paramValues.gj[1]}<br/>
6.3:java:<%=request.getParameterValues("gj")[0]%><br/>
6.4:java:<%=request.getParameterValues("gj")[1]%><br/><br/>


7:EL的11大内置对象之 header和headerValues <br/>
<%--不能通过.运算符来取 因为中间有- --%>
7.1:<%="${header.Host}="%>${header.Host}<br/>
7.2:<%="${header['Content-Length']}="%>${header['Content-Length']}<br/>
7.3:<%="${header['Connection']}="%>${header['Connection']}<br/>
7.4:<%="${header['Accept-Encoding']}="%>${header['Accept-Encoding']} <br/>
7.5:<%="${headerValues['Accept-Encoding'][0]}="%>${headerValues['Accept-Encoding'][0]} <br/>
7.6:<%="${headerValues['Connection'][0]}="%>${headerValues['Connection'][0]} <br/>

<br/>
8:EL的11大内置对象之初始化参数： initParam 取得web.xml中的context-param值<br/>

8.1:<%="${initParam.age}="%>${initParam.age}<br/>
8.2:<%="${initParam.company}="%>${initParam.company}<br/>
8.3:<%="${initParam['age']}="%>${initParam['age']}<br/>
8.4:<%="${initParam['company']}="%>${initParam['company']}<br/>
<br/>

9:EL的11大内置对象之Cookie<br/>
9.1:<%="${cookie.JSESSIONID.name}="%>${cookie.JSESSIONID.name}<br/> 
9.2:<%="${cookie.JSESSIONID.value}="%>${cookie.JSESSIONID.value}<br/>
9.3:${cookie.userEntity.name} = ${cookie.userEntity.value}

<br/><br/>

10:EL的11大内置对象之pageContext <br/>
10.1:<%="${pageContext.request.contextPath}="%>${pageContext.request.contextPath}<br/>
10.2:<%="${pageContext.request.remoteHost}="%>${pageContext.request.remoteHost}<br/>
10.3:<%="${pageContext.session.id}="%>${pageContext.session.id}<br/>
10.3:<%="${pageContext.servletContext.serverInfo}="%>${pageContext.servletContext.serverInfo}


<br/>
======================================================
<br/>
JSTL=Java Standard Taglib Language 之 c标签
<br/><br/>
1:c：out语法<br/>
1.1:<%="&lt;c:out value=\"10086\"/&gt;"%> = <c:out value="10086"/>  ${'10086'}<br/>
1.2:<%="&lt;c:out value=\"${requestScope.is}\"/&gt;"%> =<c:out value="${requestScope.is}"/> <br/>
1.3:<%="&lt;c:out value=\"${requestScope.is2}\" default=\"10088\"/&gt;"%>
=<c:out value="${requestScope.is2}" default="10088" /> <br/>

1.4 <%="&lt;c:out value=\"&lt;script&gt; alert(\"hello\"); &lt;script&gt;\" escapeXml=\"true\" /&gt;"%> 
= alert(1); <c:out value="<script>alert(1);</script>" escapeXml="true" />

<br/>
<br/>
2:c：set语法<br/>
注意： scope的默认作用域是pageScope jstl和el表达式是互通的 <br/>
2.1: <%="&lt;c:set var=\"i\" value=\"1\" scope=\"request\"/&gt;"%>
=<c:set var="i" value="1" scope="request" />${arr[requestScope.i]}=${arr[i]}
<%=request.getAttribute("i")%>

<br/>

2.2:
<%="&lt;c:set var=\"basePath\" value=\"${pageContext.request.contextPath}\" scope=\"application\"/&gt;"%>
=<c:set var="basePath" value="${pageContext.request.contextPath}" scope="application"/> ${applicationScope.basePath}
<br/>
2.3:<c:set target="${sessionScope.userEntity}" property="username" value="zhangwuji"/> ${sessionScope.userEntity.username}
<br/>
2.4:<c:set target="${requestScope.map}" property="a" value="120"/> ${requestScope.map.a}
<br/>
<br/>
3:c：remove语法<br/>
<%
	pageContext.setAttribute("domain","pageContext");
	request.setAttribute("domain","request");
	session.setAttribute("domain","session");
	application.setAttribute("domain","application");
%>
3.1:删除指定域对象中的domain:
<%="&lt:c:remove var=\"domain\" scope=\"session\"/&gt;"%><c:remove var="domain" scope="session"/><br/>
pageContext=${pageScope.domain}<br/>
request=${requestScope.domain}<br/>
session=${sessionScope.domain}<br/>
application=${applicationScope.domain}<br/>
3.2:删除所有域对象中的domain: <%="&lt:c:remove var=\"domain\" /&gt;"%><c:remove var="domain" /><br/>
pageContext=${pageScope.domain}<br/>
request=${requestScope.domain}<br/>
session=${sessionScope.domain}<br/>
application=${applicationScope.domain}<br/>

<br/>

4: c:URL语法<br/>

<%="&lt;c:url value=\"/\"/&gt;"%>=<c:url value="/"/> <br/>
<%="&lt;c:url value=\"/\" var=\"basePath\" scope=\"application\"/&gt;"%>=
<c:url value="/" var="basePath" scope="application" /> ${applicationScope.basePath}<br/>

<br/>

5:c:if语法:if标签的test属性必须是一个boolean类型的值，如果test的值为true，那么执行if标签的内容，否则不执行。<br/>
<%-- scope: page/request/session/application --%>
<c:set var="b" value="" scope="request" />
<c:if test="${not empty requestScope.b}">
	${requestScope.b} 学习
</c:if>
<c:if test="${empty requestScope.b}">
	requestScope.b is empty
</c:if>
<br/><br/>
6:c:choose语法：
score=80<c:set var="score" value="-50" />
<c:choose>
	<c:when test="${score>100 || score<0}" >错误的分数</c:when>
	<c:when test="${score>=90}">A</c:when>
	<c:when test="${score>=80}">B</c:when>
	<c:when test="${score>=70}">C</c:when>
	<c:when test="${score>=60}">D</c:when>
	<c:otherwise>E</c:otherwise>
</c:choose>

<br/><br/>
7:c:forEach语法<br/>
<%-- step= 步长 --%>

<%--
	for (int i = 0; i < 10; i++) {
		//....
	}
--%>
7.1:循环变量<br/>
<%--  step= 步长   end不包括 --%>
<c:forEach var="i" begin="0" end="9" step="1" >
	${"i="}${i}<br/>
</c:forEach>

7.2：循环集合 <br/>
<%-- 循环数组arr  index就是循环中的1项目 --%>
<%--
	String[] arr= new String[]{"Tom","John","Sam","Ban","Bob"};
	for (String item : arr) {
		System.out.println(item);
	}
--%>
<%-- varStatus获取循环的状态 --%>
7.2.1:遍历数组<br/>
<table>

<%-- 默认 begin="0" step="1"  --%>
<c:forEach var="item" items="${arr}" begin="0" step="1" varStatus="vs" >
	<c:if test="${vs.count%2==0}">
		<tr style="background-color: gray">
	</c:if>
	<c:if test="${vs.count%2==1}">
		<tr>
	</c:if>
	<td >是否是第1行：${vs.first}</td>
	<td>是否是最后1行：${vs.last}</td>   
	<td>循环中的1项： ${item}</td>  
	<td>循环的次数从1开始：${vs.count}</td> 
	<td>循环的下标从0开始：${vs.index}</td> 
	<td>当前的项目：${vs.current}</td>
	</tr>
</c:forEach>
</table>

7.2.2:遍历map:<br/>
<c:forEach var="item" items="${requestScope.map}">
	<c:out value="${item.key }:${item.value }"/><br/>
</c:forEach>
7.2.3:遍历list:<br/>
<c:forEach var="item" items="${requestScope.list}">
	<c:out value="${item}"/><br/>
</c:forEach>

<br/>
======================================================
<br/>
JSTL=Java Standard Taglib Language 之 fmt标签
<br/>

1: Date类型：
Date类型数据的原始值：${sessionScope.userEntity.date}<br/>
Date类型数据的格式化输出yyyy-MM-dd：<fmt:formatDate value="${userEntity.date}" pattern="yyyy-MM-dd HH:mm:ss" />
<br/><br/>

2： Number类型：
Number类型的原始值： ${15.236}<br/>
Number类型的格式化输出 保留2位小数（四舍五入）：<fmt:formatNumber value="${15.236}" maxFractionDigits="2" /> <br/>
Number类型的格式化输出 前面补0 4位(千分位) <fmt:formatNumber value="${15.236}" minIntegerDigits="4" /> <br/>
<%-- 0表示1个占位符 --%>
2.1: 4个整数位 2个小数位 四舍五入： <fmt:formatNumber value="${15.235}" pattern="0000.00" /> <br/>
2.2: 千分位 四舍五入： <fmt:formatNumber value="${1353252352355.2}" pattern="#,###.00" /> <br/>
2.3: 2个小数位 千分位 四舍五入： <fmt:formatNumber value="${.2}" pattern="#,###.00" /> <br/>
2.4: 补充整数位的0： <fmt:formatNumber value="${.2}" pattern="#,##0.00" /> <br/>
2.5: 2个小数位 千分位 四舍五入： <fmt:formatNumber value="${15.2}" pattern="#,###.00" /> <br/>

<br><br><br>
<a href="remove">退出</a>
</body>
</html>
